home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 015 / printpak.lbr / PRINTPAK.PQS / printpak.pas
Pascal/Delphi Source File  |  1985-11-02  |  5KB  |  187 lines

  1. {-------------------------------------------------------------------}
  2. {  High resolution graphics for Epson printers                      }
  3. {                                                                   }
  4. {  From:  Bridger, M and M Goresky  "High-Resolution Printer        }
  5. {           Graphics", Byte, vol. 10, no. 12, November 1985,        }
  6. {           pp. 219-232                                             }
  7. {-------------------------------------------------------------------}
  8. const
  9.     across = 1599;
  10.     down   =   39;
  11.  
  12. type
  13.     data_type  = array[0..across,0..down] of char;
  14.     mask_array = array[0..7] of byte;
  15.  
  16. var
  17.     Evenmap, Oddmap: ^data_type;
  18.     M, R: mask_array;
  19.  
  20.  
  21. procedure Init_mem;
  22.  
  23. var  I, J: integer;
  24.  
  25. begin  { Init_mem }
  26.  
  27.     new (Evenmap);                      {  Set aside space in       }
  28.     new (Oddmap);                       {    memory for arrays      }
  29.  
  30.     for J := 0 to down do
  31.         for I := 0 to across do begin
  32.             oddmap^[I,J]  := chr(0);    {  Initialize both arrays   }
  33.             evenmap^[I,J] := chr(0)     {    to all bytes = 0       }
  34.         end
  35.  
  36. end;  { Init_mem }
  37.  
  38.  
  39. procedure Printout;
  40.  
  41. var  n_lo, n_hi: byte;
  42.      I, J:       integer;
  43.  
  44. begin  { Printout }
  45.  
  46.     n_hi := (across+1) div 256;
  47.     n_lo := (across+1) mod 256;
  48.  
  49.     for J := 0 to down do begin
  50.  
  51.         {  Enter graphics mode, give number of bytes coming         }
  52.         write (Lst, chr(27), 'Z', chr(n_lo), chr(n_hi));
  53.         for I := 0 to across do
  54.             write (Lst, evenmap^[I,J]);     {  print even row       }
  55.         write (Lst, chr(13));               {  carriage return      }
  56.         write (Lst, chr(27), '3', chr(1));  {  set LF to 1/3 dot    }
  57.         write (Lst, chr(10));               {  linefeed             }
  58.  
  59.         {  Enter graphics mode, give number of bytes coming         }
  60.         write (Lst, chr(27), 'Z', chr(n_lo), chr(n_hi));
  61.         for I := 0 to across do
  62.             write (Lst, oddmap^[I,J]);      {  print odd row        }
  63.         write (Lst, chr(13));               {  carriage return      }
  64.         write (Lst, chr(27), '3', chr(22)); {  set LF to 7 1/3 dots }
  65.         write (Lst, chr(10))                {  linefeed             }
  66.  
  67.     end
  68. end;  { Printout }
  69.  
  70.  
  71. procedure PixelMasks;
  72.  
  73. var  I: integer;
  74.  
  75. begin  { PixelMasks }
  76.  
  77.     M[7] := 1;
  78.     for I := 6 downto 0 do
  79.         M[I] := 2 * M[I+1];
  80.     for I := 0 to 7 do
  81.         R[I] := 255 - M[I]
  82.  
  83. end;  { PixelMasks }
  84.  
  85.  
  86. {  Change given byte from present value to given value = color      }
  87. procedure Change (var Char_byte: char;  color, height: integer);
  88.  
  89. var  Old: integer;
  90.  
  91. begin  { Change }
  92.  
  93.     Old := ord (Char_byte);
  94.     case color of
  95.         1:  Old := Old OR M[height];        {  Insert set bit using }
  96.         0:  Old := Old AND R[height]        {    proper pixel mask  }
  97.     end;
  98.     Char_byte := chr(Old)
  99.  
  100. end;  { Change }
  101.  
  102.  
  103. {  Writes dot at position (x,y) in memory arrays                    }
  104. procedure Pset (x, y, color: integer);
  105.  
  106. var  I, line, height: integer;
  107.  
  108. begin  { Pset }
  109.  
  110.     {  Draw dot on screen, scaling by ratio of printer width and    }
  111.     {    height to screen width and height                          }
  112.     Plot (x * 2 div 5, y * 5 div 16, white);
  113.  
  114.     color  := color mod 2;
  115.     line   := y div 16;             {  vertical position of pixel   }
  116.     height := (y mod 16) div 2;     {   consists of line and height }
  117.  
  118.     if (y mod 2 = 0) then
  119.         change (evenmap^[x,line], color, height)
  120.     else
  121.         change (oddmap^[x,line], color, height);
  122.  
  123. end;  { Pset }
  124.  
  125.  
  126. {  Bresenham's line drawing algorithm                               }
  127. procedure Pixel_Line (x1, y1, x2, y2: integer);
  128.  
  129. var  x, y, z, a, b, dx, dy, d, deltap, deltaq: integer;
  130.  
  131. begin  { Pixel_Line }
  132.  
  133.     dx := abs (x2 - x1);
  134.     dy := abs (y2 - y1);
  135.  
  136.     if (dy <= dx) then begin                        {  Slope <= 1   }
  137.         x := x1;  y := y1;  z := x2;
  138.         if (x1 <= x2)
  139.             then  a := 1
  140.             else  a := -1;
  141.         if (y1 <= y2)
  142.             then  b := 1
  143.             else  b := -1;
  144.  
  145.         deltap := dy + dy;
  146.         d      := deltap - dx;
  147.         deltaq := d - dx;
  148.  
  149.         Pset (x, y, 1);
  150.         while (x <> z) do begin
  151.             x := x + a;
  152.             if (d < 0) then
  153.                 d := d + deltap
  154.             else begin
  155.                 y := y + b;
  156.                 d := d + deltaq
  157.             end;
  158.             Pset (x, y, 1)
  159.         end
  160.     end
  161.     else begin          {  dx <= dy, so view x as a function of y   }
  162.         y := y1;  x := x1;  z := y2;
  163.         if (y1 <= y2)
  164.             then  a := 1
  165.             else  a := -1;
  166.         if ( x1 <= x2)
  167.             then  b := 1
  168.             else  b := -1;
  169.  
  170.         deltap := dx + dx;
  171.         d      := deltap - dy;
  172.         deltaq := d - dy;
  173.  
  174.         Pset (x, y, 1);
  175.         while (y <> z) do begin
  176.             y:= y + a;
  177.             if (d < 0) then
  178.                 d := d + deltap
  179.             else begin
  180.                 x := x + b;
  181.                 d := d + deltaq
  182.             end;
  183.             Pset (x, y, 1)
  184.         end
  185.     end
  186.  
  187. end;  { Pixel_Line }